package com.school_admin;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;

/**
 * &#064;name  mybatis 代码生成
 */
public class Code {
    public static void main(String[] args) {
        String url = "jdbc:mysql:///recommend";
        String username = "root";
        String password = "root";
        String author = "";
        String moduleName = "";
        String mapperLocation = "C:\\Users\\31774\\Desktop\\school_admin\\src\\main\\resources\\mapper" + moduleName;
//        String tables = "sc_admin,sc_collection,sc_comment,sc_feedback,sc_like,sc_operation," +
//                "sc_post,sc_user";
        String tables = "sc_swiper";

        FastAutoGenerator.create(url, username, password)
                .globalConfig(builder -> {
                    builder.author(author) // 设置作者
                            //.enableSwagger() // 开启 swagger 模式
                            //.fileOverride() // 覆盖已生成文件
                            .outputDir("C:\\Users\\31774\\Desktop\\school_admin\\src\\main\\java\\"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.school_admin") // 设置父包名
                            .moduleName(moduleName) // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.xml, mapperLocation)); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude(tables) // 设置需要生成的表名
                            .addTablePrefix("sc_"); // 设置过滤表前缀
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
}